<?php
if (!defined("IN_FUSION")) { die("Access Denied"); }

$com_per_page = "5"; // Number of comments to show

openside("<img class='p-img' src='".THEME."images/title/latest_comments_panel.png' alt='' />".$locale['global_073'].""); 

$i = 0;
$result = dbquery(
"SELECT * FROM ".DB_COMMENTS." LEFT JOIN ".DB_USERS."
ON ".DB_COMMENTS.".comment_name=".DB_USERS.".user_id
ORDER BY comment_datestamp DESC LIMIT $com_per_page"
);
if (dbrows($result)) {

echo "<div class='tbl-border' style='overflow: hidden; width: 370px; border-top:0;'>";
while ($data = dbarray($result)) {
echo "<div style='width:100%;' class='".($i% 2==0?"tbl1":"tbl2")."'>\n";
echo "<span class='side-small'>\n";
echo ($data['user_avatar'] ? "<a href='".BASEDIR."profile.php?lookup=".$data['user_id']."' ><img width='40' height='40' src='".BASEDIR."images/avatars/".$data['user_avatar']."' alt='' style='float: left; padding: 0 4px 4px 0;' /></a>" : "<a href='".BASEDIR."profile.php?lookup=".$data['user_id']."' ><img width='40' height='40' src='".THEME."/images/no-avatar.jpg' alt='' style='float: left;padding: 0 4px 4px 0;' /></a>");
echo ($data['user_name'] ? " <a href='".BASEDIR."profile.php?lookup=".$data['comment_name']."'>".$data['user_name']."</a>" : $data['comment_name']."");


$comment_message = trimlink($data['comment_message'], 150);
$comment_item_id = $data['comment_item_id'];
$comment_type = $data['comment_type'];
$comment_message = parseubb(parsesmileys($comment_message), "b|i|u|url|color"); // b|i|u|url|color = bbcodes to be parsed

echo " ".$locale['global_071'].showdate("longdate", $data['comment_datestamp'])."<br />".$comment_message."<br />";

// Default PHP-Fusion Comment types
if ($data['comment_type'] == "N") {
echo " <a class='side' href='".BASEDIR."news.php?readmore=".$data['comment_item_id']."'> >>".$locale['global_072']."</a>";
}
else if ($data['comment_type'] == "A") {
echo " <a class='side' href='".BASEDIR."articles.php?article_id=".$data['comment_item_id']."'> >>".$locale['global_072']."</a>";
}

else if ($data['comment_type'] == "C") {
echo " <a class='side' href='".BASEDIR."viewpage.php?page_id=".$data['comment_item_id']."'> >>".$locale['global_072']."</a>";
}

else if ($data['comment_type'] == "P") {
echo " <a class='side' href='".BASEDIR."photogallery.php?photo_id=".$data['comment_item_id']."'> >>".$locale['global_072']."</a>";
}

//Custom Comment types
else if ($data['comment_type'] == "U") {
echo " <a class='side' href='".BASEDIR."profile.php?lookup=".$data['comment_item_id']."'> >>".$locale['global_072']."</a>";
}

else { //If it can't figure out what comment type this is
   echo " <strong>(No Link)</strong>";
}
echo "</span>";
echo "<div style='clear:both;height:0;'></div>\n</div>\n";
$i++;
}

echo "</div>\n";
} else {
echo "<center><br />".$locale['c101']."<br /><br /></center>\n";
}
closeside();

?>